package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 添加地址簿
     *
     * @param addressBook
     */
    @Insert("insert into address_book (user_id, consignee, sex, phone, province_code, province_name, city_code," +
            " city_name, district_code, district_name, detail, label) " +
            "VALUES(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode}," +
            "#{cityName},#{districtCode},#{districtName},#{detail},#{label})")
    void insert(AddressBook addressBook);

    /**
     * 动态查询sql
     * 可根据userId,isDefault,id进行动态查询
     *
     * @param addressBook
     * @return
     */
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 根据id删除地址簿信息
     *
     * @param addressBook
     */
    @Delete("delete from address_book where id=#{id}")
    void deleteById(AddressBook addressBook);

    /**
     * 根据id设置默认地址簿地址
     *
     * @param addressBook
     */
    @Update("update address_book set is_default=1 where id=#{id}")
    void updateDefault(AddressBook addressBook);

    /**
     * 根据userId清除默认地址簿
     *
     * @param addressBook
     */
    @Update("update address_book set is_default =0 where user_id=#{userId}")
    void deleteDefault(AddressBook addressBook);

    /**
     * 根据id查询地址簿
     *
     * @param id
     * @return
     */
    @Select("select *from address_book where id=#{id}")
    AddressBook getById(long id);
}
